<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>

    <meta charset="UTF-8">


    <!-- 地址栏显示 -->
    <link rel="Shortcut Icon" href="/static/images/hospital.ico" type="image/x-icon"/>
    <!-- 收藏栏也显示 -->
    <link rel="Bookmark" href="/static/images/hospital.ico" type="image/x-icon"/>

    <link href="/static/sb-admin-2/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <!--    <link th:href="@{https://fonts.loli.net/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i}"
              rel="stylesheet">-->

    <!-- Custom styles for this template-->
    <link href="/static/sb-admin-2/css/sb-admin-2.css" rel="stylesheet">

    <link href="/static/sb-admin-2/bootstrap/bootstrap-table.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/static/csss/sweetalert.css">


    <title>入库管理</title>
    <link rel="stylesheet" type="text/css" href="/static/csss/mcss/mcss_storageManage.css"/>
    <link rel="stylesheet" type="text/css" href="/static/csss/chosen.min.css"/>
    <link type="text/css" rel="stylesheet" href="/static/csss/preloader.css">
    <link rel="stylesheet" type="text/css" href="/static/csss/flatpickr.min.css"/>

    <link rel="stylesheet" href="/static/layui/css/layui.css"/>
</head>
<body>
<!--正文-->
<div>
    <div class="card shadow mb-4" style="margin-left: 2.5%;height: 800px;">

        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">入库管理</h6>
        </div>

        <div style="display: flex">
            <div class="card-body" style="width: 60%">
                <div style=" margin-left: 6%">

                    <div style="width: 40%;">
                        <ul class="nav nav-pills " role="tablist">
                            <li class="nav-item" style="text-align: center">
                                <a class="nav-link active" data-toggle="pill" href="#drugadd">药品入库</a>
                            </li>
                            <li class="nav-item" style="text-align: center">
                                <a class="nav-link" data-toggle="pill" href="#newDrugs">新增药品</a>
                            </li>
                        </ul>
                    </div>

                    <div class="tab-content addNewDrug">
                        <div id="drugadd" class=" tab-pane active"><br>
                            <form class="layui-form" action="" lay-filter="update">
                            <div style="display: flex;margin: 10px 0 20px 0">
                                <form class="layui-form" action="" lay-filter="edit">
                                    <div style="display: flex">
                                        <div>药品名</div>
                                        <div style="margin-left: 10px">
                                            <select class='drugSelect' name="name" id="drugSelect" lay-filter="drugSelect">
                                                <option value="">请选择入库的药物</option>
                                            </select>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            剂型<input type="text" id="drug_type" readonly="readonly"
                                     style="width: 150px"><br><br>
                            功效<input type="text" id="efficacy_classification" readonly="readonly"
                                     style="width: 150px">
                            制剂规格<input type="text" id="specification" readonly="readonly"
                                       style="width: 150px">
                            <br><br>
                            生产厂家<input type="text" id="manufacturer" readonly="readonly"
                                       style="width: 348px"><br><br>
                            现库存量<input type="text" id="drug_count" readonly="readonly"
                                       style="width: 140px">
                            <br><br>
                            请输入入库量<input type="text" id="drug_count2" style="width: 110px">
                            <br><br>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>


                        <div id="newDrugs" class=" tab-pane fade"><br>
                            <form class="layui-form" id="drug-add" action="" lay-filter="add">
                                <input type="hidden" name="id">
                                <div style="display: flex ; margin-bottom: 30px">
                                    药品名：<input type="text" name="name" style="width: 170px">
                                </div>
                                <div style="display: flex;margin-top: 30px; margin-bottom: 20px">
                                    <div style="display: flex">
                                    <div>剂&nbsp&nbsp&nbsp&nbsp型：</div>
                                    <div style="margin-left: 10px">
                                        <select class='drug_type' name="drug_type">
                                            <option value="">请选择剂型</option>
                                            <option value="片剂">片剂</option>
                                            <option value="胶囊剂">胶囊剂</option>
                                            <option value="注射剂">注射剂</option>
                                            <option value="薄膜衣片">薄膜衣片</option>
                                            <option value="颗粒冲剂">颗粒冲剂</option>
                                        </select>
                                    </div>
                                    </div>
                                </div>
                                制剂规格:<input type="text" name="specification" style="width: 150px">
                                制剂单位:<input type="text" name="unit" style="width: 150px"><br>
                                <div style="display: flex;margin-top: 30px">
                                    <div style="display: flex">
                                    <div>是否限制药：</div>
                                    <div style="margin-left: 10px">
                                        <select class='limit_status' name="limit_status">
                                            <option value="">是否限制药物</option>
                                            <option value="1">是</option>
                                            <option value="0">否</option>
                                        </select>
                                    </div>
                                    </div>
                                </div>
                                <div style="display: flex;margin-top: 30px">
                                    <div style="display: flex">
                                    <div>功效&nbsp&nbsp&nbsp&nbsp分类：</div>
                                    <div style="margin-left: 10px">
                                        <select class='efficacy_classification' name="efficacy_classification">
                                            <option value="">请选择功效</option>
                                            <option value="风热感冒">风热感冒</option>
                                            <option value="抗病毒药">抗病毒药</option>
                                            <option value="解热镇痛">解热镇痛</option>
                                            <option value="清热解毒">清热解毒</option>
                                        </select>
                                    </div>
                                    </div>
                                </div>
                                <div style="display: flex;margin-top:30px">
                                    <div style="width: 160px">
                                        批发价:<input type="text" name="wholesale_price" style="width: 100px">
                                    </div>
                                    <div style="width: 160px;">
                                        售&nbsp&nbsp&nbsp价:<input type="text" name="price" style="width:100px">
                                    </div>
                                    <div style="width: 160px;">
                                        入库量:<input type="text" name="drug_count" style="width:100px">
                                    </div>
                                </div>
                                <div style="display: flex;margin-top:30px">
                                    <div style="display: flex;width: 245px">
                                    <div>生产日期：</div>
                                        <input type="text" name="production_date" class="layui-input" style="width: 150px;height: 33px">
                                    </div>
                                    <div style="display: flex;width: 245px">
                                        <div>保质日期：</div>
                                        <input type="text" name="quality_date" class="layui-input" style="width: 150px;height: 33px">
                                    </div>
                                </div>
                                <div style="margin-top: 30px;margin-bottom: 30px">
                                    生产厂家：
                                    <input type="text" name="manufacturer" style="width:380px">
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit lay-filter="formDemo2">立即提交</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card-body" style="width: 40%">

                <div style="width: 40%;">
                    <ul class="nav nav-pills " role="tablist">
                        <li class="nav-item" style="text-align: center">
                            <a class="nav-link active" data-toggle="pill" href="#addDrugType">新增剂型</a>
                        </li>
                        <li class="nav-item" style="text-align: center">
                            <a class="nav-link" data-toggle="pill"
                               href="#addEfficacyClassification">新增功效</a>
                        </li>
                    </ul>
                </div>

                <div class="tab-content addNewDrug">

                    <div id="addDrugType" class=" tab-pane active" style="margin: 30px 0 0 10px"><br>
                        <form class="layui-form" id="type-add" action="" lay-filter="add2">
                        请输入剂型<input type="text" name="drug_type"  style="width: 150px">
                        <button class="layui-btn" lay-submit lay-filter="formDemo3">新增</button>
                        </form>
                    </div>


                    <div id="addEfficacyClassification" class=" tab-pane fade" style="margin: 30px 0 0 10px"><br>
                        <form class="layui-form" id="efficacyClassification-add" action="" lay-filter="add3">
                        请输入功效<input type="text" name="efficacy_classification" style="width: 150px">
                        <button class="layui-btn" lay-submit lay-filter="formDemo4">新增</button>
                        </form>
                    </div>
                </div>


            </div>
        </div>
    </div>
</div>

</div>
</div>
</div>
<div>
    <div>

        <script type="text/javascript" src="/static/sb-admin-2/vendor/jquery/jquery.min.js"></script>

        <script type="text/javascript" src="/static/sb-admin-2/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

        <!-- Core plugin JavaScript-->
        <script type="text/javascript" src="/static/sb-admin-2/vendor/jquery-easing/jquery.easing.min.js"></script>

        <!-- Custom scripts for all pages-->
        <script type="text/javascript" src="/static/sb-admin-2/js/sb-admin-2.min.js"></script>
        <script type="text/javascript" src="/static/jss/sweetalert-dev.js"></script>
    </div>
    <script type="text/javascript" src="/static/jss/jquery.preloader.min.js"></script>
    <script type="text/javascript" src="/static/jss/chosen.jquery.min.js"></script>
    <script src="/static/sb-admin-2/bootstrap/bootstrap-table.min.js"></script>
    <script src="/static/sb-admin-2/bootstrap/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript" src="/static/jss/flatpickr.min.js"></script>
    <script src="/static/js/jquery-3.3.1.js"></script>
    <script src="/static/layui/layui.js"></script>
    <script>
        <!--方法-->
        <!--控制队列-->
        <!--页面加载获取方法的品和相应信息-->
        window.onload = function () {
            //获取所有药品
            getAllDrug();
        };

        //获取所有药品
        function getAllDrug() {
            layui.use(['form', 'laydate'], function () {
                // layui引入需要的组件
                var $ = layui.jquery;
                var layer = layui.layer;
                var form = layui.form;
                // 二级联动 第一步 渲染父级
                $.ajax({
                    url: '/drug/findAll',	// 后台取到所有的药物名称
                    dataType: 'json',
                    type: 'post',
                    success: function (resData) {
                        console.log(resData);
                        $.each(resData.data.list, function (index, value) {
                            console.log(value)
                            // 这里的 value.roomName
                            // 前者是页面显示的值，后者是传递给后台的值。
                            // 正常情况下，后者应该是 value.id
                            $('#drugSelect').append('<option value="' + value.name + '">' + value.name + '</option>');	// 下拉菜单里添加元素
                        });
                        //渲染select
                        form.render('select');
                    }
                })
                // 第二步 监听父级，每当父级发生变化时，渲染子级的值
                form.on('select(drugSelect)', function (data) {
                    var name = data.value; // name 选中的药物名称
                    console.log(name)
                    $.ajax({
                        url: '/drug/findAll',
                        dataType: 'json',
                        type: 'post',
                        data: {name: name},
                        success: function (resData) {
                            console.log(data)
                            $.each(resData.data.list, function (index, value) {
                                // 这里的 value.bedNo
                                // 前者是页面显示的值，后者是传递给后台的值。
                                // 正常情况下，后者应该是 value.id
                                $("#specification").val(value.specification);
                                $("#price").val(value.price)// 下拉菜单里添加元素
                            });
                            //渲染select
                            form.render('select');
                        }
                    });
                });
            });
        }

        //Demo
        layui.use(['form', 'laydate'], function () {
            var form = layui.form
                , laydate = layui.laydate;
            laydate.render({
                elem: '#quality_date'
            });
            laydate.render({
                elem: '#production_date'
            });
            //监听提交
            form.on('submit(formDemo)', function (data) {
                var data1 = form.val("edit");
                $.ajax({
                    url: '/drug/upd',
                    type: "post",
                    dataType: "json",
                    data: data1,
                    success: function (da) {
                        console.log(da)
                        if (da.code == 200) {
                            layer.alert("入库成功！", function () {
                                // window.parent.location.reload();//刷新父页面
                                // parent.layer.close(layer.index);//关闭弹出层
                                window.location.href="/view/drug/list.html";
                                parent.layer.closeAll();
                            });
                        } else {
                            layer.msg("入库失败！");
                        }
                    }
                });
                return false;
            });
            //监听提交
            form.on('submit(formDemo2)', function (data) {
                var data1 = form.val("add");
                console.log(data1)
                $.ajax({
                    url: '/drug/add',
                    type: "post",
                    dataType: "json",
                    data: data1,
                    success: function (da) {
                        if (da.code == 200) {
                            layer.alert("添加成功！", function () {
                                //window.parent.location.reload();//刷新父页面
                                //parent.layer.close(layer.index);//关闭弹出层
                                window.location.href="/view/drug/list.html";
                                parent.layer.closeAll();
                            });
                        } else {
                            layer.msg("添加失败！");
                        }
                    }
                });
                return false;
            });
            form.on('submit(formDemo3)', function (data) {
                var data1 = form.val("add2");
                console.log(data1)
                $.ajax({
                    url: '/type/add',
                    type: "post",
                    dataType: "json",
                    data: data1,
                    success: function (da) {
                        if (da.code == 200) {
                            layer.alert("添加成功！", function () {
                                //window.parent.location.reload();//刷新父页面
                                //parent.layer.close(layer.index);//关闭弹出层
                                window.location.href="/view/drug/add.html";
                                parent.layer.closeAll();
                            });
                        } else {
                            layer.msg("添加失败！");
                        }
                    }
                });
                return false;
            });
            form.on('submit(formDemo4)', function (data) {
                var data1 = form.val("add3");
                console.log(data1)
                $.ajax({
                    url: '/effect/add',
                    type: "post",
                    dataType: "json",
                    data: data1,
                    success: function (da) {
                        if (da.code == 200) {
                            layer.alert("添加成功！", function () {
                                //window.parent.location.reload();//刷新父页面
                                //parent.layer.close(layer.index);//关闭弹出层
                                window.location.href="/view/drug/add.html";
                                parent.layer.closeAll();
                            });
                        } else {
                            layer.msg("添加失败！");
                        }
                    }
                });
                return false;
            });
        });
    </script>
</div>
</body>
</html>